home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Spinning Text ƒ / Spinning Text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  5.7 KB  |  196 lines  |  [TEXT/KAHL]

  1. /*
  2.     Spinning text
  3.     
  4.     This application will create a line of text, set the text to an hsv color, rotate, and draw 
  5.     the text.
  6.     
  7.     
  8.     NOTES:
  9.     • This file requires the following files to run correctly:
  10.         "graphics shell.c", "FontLibrary.c", "GraphicsDebugLibrary.c", "TransformLibrary.c".
  11.  
  12.     • For the best printing results, print this file in "landscape".
  13.     
  14.     
  15.     Change History:
  16.  
  17.        4/96    bob        Updated #includes to support changed GX Library names.
  18.                     Changed fixed to Fixed.
  19.                     Updated the note regarding the files needed to run.
  20.                     Updated the copyright date.
  21.  
  22.     ©1990-1996 Apple Computer, Inc.
  23.     All rights reserved.
  24. */
  25.  
  26. #include <Events.h>
  27. #include <Windows.h>
  28.  
  29. #include "GraphicsLibraries.h"
  30. #include <GXEnvironment.h>
  31. #include "FontLibrary.h"
  32. #include "graphics shell.h"
  33.  
  34. #define kNumberOfTextStringsDrawn    19
  35.  
  36. //
  37. //  Set up the title and size of the window 
  38. //
  39. Str255         gWindowTitle = "\p Spinning Text ";         
  40. Rect         gWindowQDRect  = {50, 10, 440, 440};
  41.  
  42. //
  43. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  44. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  45. //    but these  functions will not work. The "debugging" version of the QuickDraw GX init is approximately 700K.
  46. //
  47. Boolean        gDebugging = true;
  48.  
  49.  
  50. //
  51. //     Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  52. //
  53. Boolean        gGiveMeValidation = true;
  54.  
  55.  
  56. //
  57. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  58. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  59. //    With  gGraphicsHeapSize set to 15k, I had 4 free blocks left in the graphics gxHeap. Sounds good to me.
  60. //
  61. long        gGraphicsHeapSize = 15;
  62.  
  63. gxShape     gTextShape;
  64. gxColor     gTextColor;
  65. short         gTotalNumberOfTextStringsDrawn;
  66. short         gDegreesToRotateText;
  67. Fixed        gShapesXCoordinateCenter,gShapesYCoordinateCenter;
  68.  
  69.  
  70.  
  71. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  72.  
  73. void DoInitialization(aWindow)
  74. WindowPtr aWindow;
  75. {
  76.     gxPoint            textPostion;
  77.     gxRectangle     textShapeBounds;
  78.     
  79.     gTotalNumberOfTextStringsDrawn = 0;
  80.     gDegreesToRotateText = 20;
  81.  
  82.     //
  83.     //    Set up the starting text postion. This location will be set up when we
  84.     //    create our text gxShape.
  85.     //
  86.     textPostion.x = ff(50);
  87.     textPostion.y = ff(200);
  88.     
  89.     //
  90.     //  Create the text, and set the gxFont and size.
  91.     //
  92.     gTextShape = GXNewText(13,(unsigned char*)"QuickDraw™ GX", &textPostion);
  93.     SetShapeCommonFont(gTextShape, timesFont);
  94.     GXSetShapeTextSize(gTextShape, ff(45));
  95.  
  96.     //
  97.     //    A gxColor, to run through hsv space with... 
  98.     //
  99.     gTextColor.space                     = gxHSVSpace;
  100.     gTextColor.profile                     = nil;
  101.     gTextColor.element.hsv.hue             = 0x2700;
  102.     gTextColor.element.hsv.saturation     = 0xFFFF;
  103.     gTextColor.element.hsv.value         = 0xFFFF;
  104.  
  105.     //
  106.     //    Get the bounds of our text gxShape. We will then determine the center of the gxShape. 
  107.     //    The center of the gxShape will be used below in GXRotateShape which will enable us to rotate
  108.     //    our gxShape around it's center.
  109.     //
  110.     GXGetShapeBounds(gTextShape, 0L, &textShapeBounds);
  111.     gShapesXCoordinateCenter = textShapeBounds.left + textShapeBounds.right >> 1;
  112.     gShapesYCoordinateCenter = textShapeBounds.top + textShapeBounds.bottom >> 1;
  113.     
  114.     GXSetShapeAttributes (gTextShape, gxMapTransformShape);
  115. }
  116.  
  117.  
  118.  
  119. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  120.  
  121. void DoDraw(aWindow)
  122. WindowPtr aWindow;
  123. {
  124.     if (gTotalNumberOfTextStringsDrawn == kNumberOfTextStringsDrawn) 
  125.     {
  126.         gxMapping textShapeMap;
  127.         
  128.         //
  129.         //  The text  has been rotated 360 degrees. Let's erase the contents of the window
  130.         //    and reset the Shape's Transform. By resetting the Transform will reset the Transform
  131.         //    back to the GX default gxTransform (i.e. no rotate). 
  132.         //
  133.         //    With the call to GXRotateShape below, we have been only effecting the Shape's gxTransform 
  134.         //    instead of the Shape's geometry because we had set the gxMapTransformShape attribute above.
  135.         //
  136.         SetPort (aWindow);
  137.         EraseRect(&(aWindow)->portRect);
  138.  
  139.         GXGetTransformMapping(GXGetShapeTransform(gTextShape), &textShapeMap);
  140.         ResetMapping(&textShapeMap);
  141.     
  142.         //
  143.         //  Reverse the rotation direction
  144.         //
  145.         gDegreesToRotateText = -gDegreesToRotateText;
  146.     
  147.         gTotalNumberOfTextStringsDrawn = 0;
  148.     }
  149.     
  150.     GXSetShapeColor(gTextShape, &gTextColor);
  151.     GXDrawShape (gTextShape);
  152.  
  153.     GXRotateShape(gTextShape, ff(gDegreesToRotateText), gShapesXCoordinateCenter, gShapesYCoordinateCenter);
  154.     
  155.     gTextColor.element.hsv.hue += 0x0900;
  156.  
  157.     gTotalNumberOfTextStringsDrawn++;
  158. }
  159.  
  160.  
  161. /*------ DoDispose -------------------------------------------------------------------------------------*/
  162.  
  163. void DoDispose(aWindow)
  164. WindowPtr aWindow;
  165. {
  166.     //  
  167.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  168.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  169.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  170.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  171.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  172.     //
  173.     GXDisposeShape(gTextShape);  
  174.     GXDisposeShape(gWindowBoundsShape);  
  175.        DisposeWindow(aWindow);
  176. }
  177.     
  178.  
  179.  
  180. /*------ DoClick ---------------------------------------------------------------------------------------*/
  181.  
  182. void DoClick( orgMouseLoc, theWindow )
  183. gxPoint        orgMouseLoc;
  184. WindowPtr     theWindow;
  185. {
  186. }
  187.  
  188.  
  189. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  190.  
  191. void DoIdle(aWindow)
  192. WindowPtr aWindow;
  193. {
  194.     DoDraw(aWindow); 
  195. }
  196.